<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../bootstrap/css/bootstrap-grid.min.css">
    <script src="../bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="../jquery/jquery-3.7.0.min.js"></script>
    <style>
        html,
        body {
            height: 100%;
            background-color:darkgray;
        }
    </style>
</head>

<body>
    <div class="container-fluid h-100">
        <div class="row h-100 w-40 flex-row-reverse align-items-center">
            <div class="col-md-2"></div>
            <div class="card col-md-4">
                <div class="card-header mt-2">
                    登录
                </div>
                <form id="loginForm">
                    <div class="mb-3">
                        <label for="phone" class="form-label">手机号</label>
                        <input type="number" class="form-control" id="phone">
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">密码</label>
                        <input type="password" class="form-control" id="password">
                    </div>
                    <div class="mb-3">
                        <label for="verifyCode" class="form-label">验证码</label>
                        <div class="input-group">
                            <input type="text" class="form-control" id="verifyCode">
                            <div class="input-group-append">
                                <img id="captcha" src="/common/captcha" alt="captcha"
                                    onclick="$('#captcha').attr('src', '/common/captcha')">
                            </div>
                        </div>
                    </div>

                    <button type="submit" class="btn btn-primary mb-3">登录</button>
                </form>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            $('#loginForm').submit(function (e) {
                e.preventDefault;
                $.ajax({
                    url: '/user/login',
                    type: 'post',
                    data: {
                        phone: $('#phone').val(),
                        password: $('#password').val(),
                        verifyCode: $('#verifyCode').val()
                    },
                    success: function (data) {
                        if (data.code == 200) {
                            window.location.href = '/index.html';
                        } else {
                            alert(data.message);
                        }
                    }
                })
            });
        });
    </script>
</body>

</html>